<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正则表达式2</title>
</head>
<body>
    <h1>正则表达式(元字符)</h1>
</body>
<script>
    /*
    var reg=/^\d$/;//数字开头
    console.log(reg.test(1));//true
    console.log(reg.test(0));//true
    console.log(reg.test("a"));//false
    */
   /*
    var reg=/^\D$/;//非数字开头
    console.log(reg.test(1));//false
    console.log(reg.test("_"));//true
    console.log(reg.test("a"));//true
    */
   /*
    var reg=/^\w$/;//匹配字母数字下划线等价于[A-Z0-9a-z]
    console.log(reg.test(1));//true
    console.log(reg.test("_"));//true
    console.log(reg.test("a"));//true
    console.log(reg.test("$"));//false
    */
   /*
    var reg=/^\W$/;//匹配非字母数字下划线等价于[^A-Z0-9a-z]
    console.log(reg.test(1));//false
    console.log(reg.test("_"));//false
    console.log(reg.test("a"));//false
    console.log(reg.test("$"));//true
*/
    //  \t \r \n \f ==\s 任何空白字符,包括空格、换行、换页、回车、制表符
    /*
    var reg=/^\s$/;
    console.log(reg.test(" "));
    console.log(reg.test("\n"));
    console.log(reg.test("\r"));
    console.log(reg.test("\t"));
    console.log(reg.test("\f"));
    */
   //除\r\n外任何字符
   /*
   var reg=/^.$/;
   console.log(reg.test(" "));//true
   console.log(reg.test("."));//true
   console.log(reg.test("\n"));//false
   console.log(reg.test("\r"));//false
   console.log(reg.test("\t"));//true
    */
   //()括起来的代表一个整体
   var reg=/^a(bc)*$/;
   console.log(reg.test("ab"));//false
   console.log(reg.test("abc"));//true
   console.log(reg.test("abcabc"));//false

   //正则替换
   var t="今天真鸡儿冷...WC";
   var reg=/鸡儿|WC/g;
   var ok=t.replace(reg,"TMD");//replace既支持字符串,也支持正则表达式
   console.log(ok)

   //正则匹配
   var st="中国移动10086 中国电信10000 中国联通10010";
   var mval=st.match(/\d{5}/g);
   console.log(mval);
    //获取年月日    ()分组
   var d='CSDN2005-10-13 菜鸟教程2004-06-25 Java 2000-01-01';
   var data=d.match(/(\d{4})-(\d{2})-(\d{2})/g);
   console.log(data);
   console.log(RegExp.$1);//年
   console.log(RegExp.$2);//月
   console.log(RegExp.$3);//日
   var html = `
    <li class="list-item"><div class="equipment-item"><div class="prop-box"><img src="https://game.gtimg.cn/images/lol/act/img/item/1033.png" alt="抗魔斗篷"></div> <p class="prop-name">抗魔斗篷</p> <div class="price"><i class="icon-gold"></i> <span>450</span></div></div></li>
    <li class="list-item"><div class="equipment-item"><div class="prop-box"><img src="https://game.gtimg.cn/images/lol/act/img/item/1037.png" alt="十字镐"></div> <p class="prop-name">十字镐</p> <div class="price"><i class="icon-gold"></i> <span>875</span></div></div></li>
    `
    var pic=/https:\/\/.*\.png|jpg$/g;
    var src=html.match(pic);
    console.log(src);
</script>
</html>